package typejump.commands;

import java.awt.event.KeyEvent;

import typejump.Messenger;
import typejump.Settings;
import typejump.TypeJump;
import typejump.engine.GameEngine;
import typejump.engine.OnGoingThing;
import typejump.objects.Actor;

public class DevEnableArrowKeys implements TextCommand, OnGoingThing {

	private double speed = Settings.getDouble("player.cheatspeed");
	
	@Override
	public boolean matches(String command) {
		return command.equalsIgnoreCase("dev eak");
	}

	@Override
	public void act(String command) {
		GameEngine.addOnGoingThing(this);
		GameEngine.addTextEffect("ENABLE ARROW KEYS", "dev");
		Messenger.addBriefMessage("disable panning");
	}

	@Override
	public boolean happen(TypeJump tj, double seconds) {
		Actor p = tj.getPlayer();
		
		if (tj.isKeyDown(KeyEvent.VK_LEFT)) {
			p.vx(-speed);
		} else if (tj.isKeyDown(KeyEvent.VK_RIGHT)) {
			p.vx(speed);
		} else {
			p.vx(0);
		}
		
		if (Messenger.consumeMessage("keydown " + KeyEvent.VK_UP)) {
			GameEngine.addCommand("jump");
		} else if (Messenger.consumeMessage("keydown " + KeyEvent.VK_DOWN)) { 
			GameEngine.addCommand("fall");
		}

		if(Messenger.consumeMessage("disable arrow keys")) {
			return true;
		}
		return false;
	}

}
